<?
		$highest = getOne("SELECT max(rank) FROM gridimage_similarity WHERE portal_id = $portal_id");
		
		if (empty($highest)) {
			die("sorry not available on this portal");
		}
		
		$div = intval($highest/$sql['limit']);
		if ($div < 1) {
			$div = 1;
		}
		
		
		$sql['tables'][] = "INNER JOIN gridimage_similarity gsi USING (gridimage_id)";
		
		$sql['wheres'][] = "gsi.portal_id = $portal_id";
		
		$sql['wheres'][] = "rank mod $div = 0";
		
		$sql['order'] = "rank DESC, ".$sql['order'];
		
		function searchbreak(&$c,$start='',$end='') {
			if (empty($c)) {//its the last one
				print $end;
				return;
			}
			return true; //we dont disable any images...
		}
		
		
		$opt['title'] = "Sample of images in descending similarity order";